<?php


namespace app\shop\controller\api;


use app\BaseController;
use app\manage\model\Config;
use app\shop\service\config\ConfigService;

class IndexController extends BaseController
{
    /**
     *获取系统信息
     * @return \think\response\Json
     */
    public function getSystemInfo()
    {
        try {
            $config = ConfigService::getConfigValue('sysInfo');
            $config['chatInfo'] = ConfigService::getConfigValue('chatInfo');
            $config['bell'] = 'https://download8090.oss-cn-hongkong.aliyuncs.com/bell/14060.mp3';
            return $this->success($config);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 检查app版本升级
     * @return \think\response\Json
     */
    public function checkVersion()
    {
        try {
            $version = $this->request->param('version', '0.0.0');
            $platform = $this->request->param('platform', 'andriod');

//            $config = config('version.'.$platform);
//            $configVersion = $config['version'];
            $config = ConfigService::getConfigValue('sysInfo');
            $configVersion = $config['version'];
            if (version_compare($version, $configVersion) == -1) {
                $data = [
                    'other' => 'https://www.hnytw.cn/app.wgt',
                    'huawei' => 'https://www.hnytw.cn/huawei.wgt'
                ];
                return $this->success($data, '版本过低', -2);
            }
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 服务协议
     * @return \think\response\Json
     */
    public function serviceProtocol()
    {
        try {
            $data = ConfigService::getConfigValue('service_protocol');
            return $this->success($data);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 隐私协议
     * @return \think\response\Json
     */
    public function privacyPolicy()
    {
        try {
            $data = ConfigService::getConfigValue('privacy_policy');
            return $this->success($data);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }
}